App.controller('stockSupplierController', ['$rootScope', '$scope', '$state', 'Page', function($rootScope, $scope, $state, Page) {

    $scope.grid = {
        add : function() {
            $scope.stockSupplier = {};
            $scope.modal.setTitle('新增').show();
        },
        update: function(row) {
            $scope.stockSupplier = row;
            $scope.modal.setTitle('编辑').show();
        },
        save : function() {
            $scope.stockSupplier.status = '1';
            Page.ajaxPost($scope.stockSupplier.supplierId ? 'stockSupplier/update.do' : 'stockSupplier/add.do', $scope.stockSupplier, function() {
               $scope.grid.query();
               $scope.grid.cancel();
            });
        },
        column_defs: [{
            target : 6,
            buttons : [
                {
                    name: '编辑',
                    class: 'btn-warning btm-sm',
                    icon: 'fa-edit',
                    event: 'update'
                },
                {
                    name: '删除',
                    class: 'btn-danger',
                    icon: 'fa-close',
                    event: function(row) {
                        Page.confirm("确定要删除吗？", function() {
                            Page.ajaxPost('stockSupplier/delete.do', row, function() {
                                $scope.grid.query();
                            });
                        });
                    }
                }
            ]
        }]
    };

    /*自定义查询*/
    $scope.query = function () {
        $scope.grid.query();
    };

    /*自定义重置*/
    $scope.reset = function () {
        $scope.grid.reset();
    };
}]);